package com.qfedu.microorder.recharge.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.qfedu.common.core.entity.Recharge;
import com.qfedu.common.core.utils.UserUtils;
import com.qfedu.microorder.recharge.mapper.RechargeMapper;
import com.qfedu.microorder.recharge.param.RechargeParam;
import com.qfedu.microorder.recharge.service.RechargeService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Classname RechargeServiceImpl
 * @Description TODO
 * @Date 2025-06-04 11:44
 * @Created by 老任与码
 */
@Service
public class RechargeServiceImpl implements RechargeService {

    @Resource
    private RechargeMapper rechargeMapper;

    @Override
    public String addRecharge(RechargeParam rechargeParam) {

        Integer uid = UserUtils.getUid();

        Recharge recharge = new Recharge();
        BeanUtils.copyProperties(rechargeParam, recharge);
        recharge.setUid(uid);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String orderNo = sdf.format(new Date()) + RandomUtil.randomNumbers(6);
        recharge.setOrderNo(orderNo);
        rechargeMapper.insert(recharge);

        return orderNo;
    }

}
